
#include "stdafx.h"
#include "ParamYcadd.h"
#include "CommDefine.h"

CParamYcadd::CParamYcadd(bool bSimulate) :CWebParameter(bSimulate, POLICY::Key[POLICY::YcAdd])
{
}

static CParamYcadd defaultProp[] = {
	CParamYcadd(false), CParamYcadd(true)
};
CParamYcadd& CParamYcadd::defaultValue(bool bSimulate)
{
	intptr_t id = (bSimulate ? 1 : 0);
	if (!defaultProp[id].m_initialized)
	{
		if (!bSimulate)
			defaultProp[id].ReadSimulate();
		else
		{
			const intptr_t defAdd[] = {
				8, 8, 7, 7, 6, 6, 6, 6, 6, 6,
				5, 5, 5, 5, 5, 4, 4, 4, 3, 3,
				3, 2, 2, 1, 1, 0, 0, 0, 0, 0
			};
			for (intptr_t i = 0; i < PROPYcadd_COUNT; i++) defaultProp[id].m_addPrice[i] = defAdd[i];
		}
		defaultProp[id].m_initialized = true;
	}
	return defaultProp[id];
}

void CParamYcadd::readINI(const CINIOperater *oper)
{
	CParamYcadd &def = CParamYcadd::defaultValue(m_bSimulate);
	for (intptr_t i = 0; i < PROPYcadd_COUNT; i++)
	{
		wchar_t key[100]; swprintf_s(key, L"AddPrice%d", (int)(i + 30));
		m_addPrice[i] = oper->GetIntWithRange(section, key, (int)def.m_addPrice[i], 0, 30);
	}
}

void CParamYcadd::writeINI(CINIOperater *oper) const
{
	for (intptr_t i = 0; i < PROPYcadd_COUNT; i++)
	{
		wchar_t key[100]; swprintf_s(key, L"AddPrice%d", (int)(i + 30));
		oper->WriteInt(section, key, (int)m_addPrice[i]);
	}
}
